#ifndef evdictbase_h
#define evdictbase_h

/*
	Ten file: evdictbase.h
	(E-V dictionary base)
	To chuc cac ham co so dung trong chuong trinh
*/

#include "evdictstruct.h"

#define FAILED (-1)
#define SUCCEEDED 1
#define TRUE 1
#define FALSE 0
#define NOT_FOUND (-1)

// Ham nap du lieu tu file Index.dat vao bang bam
// Dau vao: bang bam, duong dan den file Index.dat
// Dau ra: SUCCEEDED neu nap thanh cong, nguoc lai tra ve FAILED
boolean loadData(char * pathIndex,char * pathRemovedRecord);

// Ham lay ve dia chi cua tu trong file Dictionary.dat dua vao ma bam
// Dau vao: bang bam, ma bam
// Dau ra: NOT_FOUND(-1) neu khong tim thay, neu tim thay thi tra ve dia chi
int getWordAddress(char* word, char* hashCode);

// Ham lay ve noi dung cua tu trong file Dictionary.dat dua vao dia chi
// Dau vao: duong dan den file Dictionary.dat, dia chi cua tu
// Dau ra: noi dung cua tu(WordMean)
WordDefinition getWordDefinitionByAddress(char* path, int address);

// Ham ghi 1 tu vao file Dictionary.dat
// Dau vao: noi dung tu(WordMean), duong dan den file Dictionary.dat
// Dau ra: dia chi cua tu neu ghi thanh cong, nguoc lai tra ve FAILED
int writeWordToFile(WordDefinition word, char* path);

// Chong ham writeWordToFile: chuyen them dia chi neu muon ghi de 1 tu co san
// Dau vao: noi dung tu(WordMean), duong dan den file Dictionary.dat, dia chi muon ghi
// Dau ra: SUCCEEDED neu ghi thanh cong, nguoc lai tra ve FAILED
//************************************
// Method:    writeWordToFile
// FullName:  writeWordToFile
// Access:    public 
// Returns:   int
// Qualifier:
// Parameter: WordDefinition word
// Parameter: char * path
// Parameter: int address
//************************************
void writeWordToFile(WordDefinition word, char* path, int address);

// Chong ham writeWordToFile: chuyen tham so WordIndex de ghi 1 tu vao file Index.dat
// Dau ra: SUCCEEDED neu ghi thanh cong, nguoc lai tra ve FAILED
int writeWordToFile(WordIndex word, char* path);

// Ham ghi tu va dia chi tu vao bang bam
void addWordToHashTable(char* word, char* hashCode, int address);

// Ham xoa 1 tu trong file Index.dat
// Dau vao: 1 tu, duong dan den file Index.dat
// Dau ra: SUCCEEDED neu xoa thanh cong, nguoc lai tra ve FAILED
boolean deleteWordFormIndex(char* word, char* path);

// Ham xoa 1 tu trong bang bam
void deleteWordFromHashTable(char* word, char* hashCode);

//Ham them 1 dia chi vao ds backup 
void addWordToBackUpList(int address);

// Ham kiem tra xem ds backup co rong hay ko
//************************************
// Method:    isBackupListEmpty
// FullName:  isBackupListEmpty
// Access:    public 
// Returns:   boolean
// Qualifier:
//************************************
boolean isBackupListEmpty();

// Lay ra 1 phan tu trong ds backup
//************************************
// Method:    getAvailableAddress
// FullName:  getAvailableAddress
// Access:    public 
// Returns:   int
// Qualifier:
//************************************
int getAvailableAddress();

//************************************
// Method:    updateBackupList
// FullName:  updateBackupList
// Access:    public 
// Returns:   void
// Qualifier:
//************************************
void updateBackupFile();


//************************************
// Method:    updateIndexFile
// FullName:  updateIndexFile
// Access:    public 
// Returns:   void
// Qualifier:
//************************************
void updateIndexFile();




/************************************************************************/
/* Test something ...                                                                     */
/************************************************************************/
void search(char * word);
WordList* findWordInHashTable(char * word);
WordList* findWordInHashTable(char * word,char * hashCode);

#endif